[mirrors]
http://ftp.kernel.org/pub/linux/utils/kbd/kbd-1.15.3.tar.xz
http://ftp.cc.uoc.gr/mirrors/ftp.kernel.org/pub/linux/utils/kbd/kbd-1.15.3.tar.xz

[vars]
filesize=761072
sha512=19dba103f4941b975f547e229d1b03c8d355cd59871e4dfe6db32235a7983b2d8f52e6c7a674d07bdef8bf3a557eefaf731eb47128c3db02f43e91192faea03c

[deps]
bison
gcc4

[build]
# fix build errors on non-glibc (first patch) and other things as described by LFS
# see http://www.linuxfromscratch.org/lfs/view/stable/chapter07/console.html
# for further reference on how this package is supposed to be used, we only use it
# to strip the keymaps off.
for p in kbd kbd-1.15.3-upstream_fixes-1 kbd-1.15.3-backspace-1 kbd-1.15.3-busyboxkmap ; do
	patch -p1 < "$K"/$p.patch
done

#fix bug in spanish transl.
sed -i '/guardado\ el/s/\(^.*en\ %\)\(.*\)/\14\$\2/' po/es.po

# prevent autoconf to be run again because of an invalid timestamp
sed -i 's/\(RESIZECONS_PROGS=\)yes/\1no/' configure &&
sed -i 's/resizecons.8 //' man/man8/Makefile.in &&
touch -d '2011-05-07 08:30' configure.ac

[ -n "$CROSS_COMPILE" ] && xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/')"

CFLAGS="-D_GNU_SOURCE -DSIGIOT=SIGABRT $optcflags" \
LDFLAGS="$optldflags" \
./configure -C --prefix="$butch_prefix" \
  --disable-nls $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

#http://hg.slitaz.org/wok/file/3f989c266063/kbd-base/stuff/keymaps-path.list
slitaz_set=`cat << EOF
azerty/be-latin1.map.gz
azerty/fr-latin1.map.gz
dvorak/dvorak.map.gz
dvorak/dvorak-r.map.gz
dvorak/dvorak-l.map.gz
qwerty/br-abnt2.map.gz
qwerty/cf.map.gz
qwerty/cz-lat2.map.gz
qwerty/dk-latin1.map.gz
qwerty/es.map.gz
qwerty/fi-latin1.map.gz
qwerty/it.map.gz
qwerty/is-latin1.map.gz
qwerty/jp106.map.gz
qwerty/nl2.map.gz
qwerty/no-latin1.map.gz
qwerty/pl2.map.gz
qwerty/pt-latin1.map.gz
qwerty/ru.map.gz
qwerty/se-lat6.map.gz
qwerty/tr_q-latin5.map.gz
qwerty/trq.map.gz
qwerty/uk.map.gz
qwerty/us-acentos.map.gz
qwerty/us.map.gz
qwertz/croat.map.gz
qwertz/de_CH-latin1.map.gz
qwertz/de-latin1.map.gz
qwertz/de-latin1-nodeadkeys.map.gz
qwertz/fr_CH-latin1.map.gz
qwertz/hu.map.gz
qwertz/sg-latin1.map.gz
qwertz/slovene.map.gz
EOF
`
# slitaz installs only these files to save space.
# so do we
# see http://hg.slitaz.org/wok/file/3f989c266063/kbd-base/receipt

fs=$butch_install_dir$butch_prefix
# generate busybox loadkmap compatible keymaps from the gnu ones.
# taken from http://hg.slitaz.org/wok/file/3f989c266063/kbd-busybox/receipt
mkdir -p "$fs"/share/kmap
for i in $slitaz_set ; do
	k=$(basename $i)
	k=${k%.map.gz} # strips off .map.gz from $k
	"$fs"/bin/loadkeys -b "$fs"/share/keymaps/i386/$i > "$fs"/share/kmap/$k.kmap || echo "ERROR: loadkeys...$i"
done

replace_stuff=true

if $replace_stuff ; then

# we can rm the original keymaps now to save space,
# and everything else, except of "$fs"/share/kmap
for i in bin share/consolefonts share/consoletrans share/keymaps share/man share/unimaps ; do
	rm -rf "$fs"/"$i"
done

# slitaz comes with a user friendly keyboard switched script: http://trixarian.net/paste/9abcb
# (/sbin/tazkeymap). this can serve as a template. for now, just use loadkmap < /share/kmap/layout.kmap

mkdir -p "$fs"/bin
cat << EOF > "$fs"/bin/loadkeys
#!/bin/sh
echo 'use loadkmap < /share/kmap/layout.kmap to change keyboard layout'
echo "available keyboard layouts are:"
find /share/kmap -name '*.kmap' | sort
exit 1
EOF
chmod +x "$fs"/bin/loadkeys

fi
